package com.df.resources.config;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class CommonConfig {

    @Value("${nacos.config.server-addr}")
    private String rigsitryAddr;

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @ConditionalOnMissingBean(NamingService.class)
    @Bean
    public NamingService namingService() throws NacosException {
        return NacosFactory.createNamingService(rigsitryAddr);
    }
}
